import BaseApi from "@/api/BaseApi.ts";
import type IPageResp from "@/type/IPageResp.ts";
import type ISysRoleReq from "../type/req/ISysRoleReq.ts";
import type ISysRoleResp from "../type/resp/ISysRoleResp.ts";
import type SysRolePermissionReq from "@/view/role/type/req/SysRolePermissionReq.ts";
import type SysRolePermissionResp from "@/view/role/type/resp/SysRolePermissionResp.ts";

class SysRoleApi extends BaseApi {

    constructor() {
        super("/rbac/sysRole")
    }

    /**
     * 分页查询
     */
    page = (sysRoleReq: ISysRoleReq) => {
        return this.get<IPageResp<ISysRoleResp>, ISysRoleReq>('page', sysRoleReq)
    }

    /**
     * 根据id查询用户
     */
    queryById = (id: String) => {
        return this.get('queryById', {id})
    }

    /**
     * 根据有无id新增或编辑用户
     */
    addOrUpdate = (sysRoleReq: ISysRoleReq) => {
        return this.post<string, ISysRoleReq>('addOrUpdate', sysRoleReq)
    }

    /**
     * 根据id删除用户
     */
    deleteById = (ids: string[]) => {
        return this.delete<string>('delete', ids)
    }

    /**
     * 查询角色授权信息
     */
    listRolePermissions = (roleId: string) => {
        return this.get<SysRolePermissionResp[], { roleId: string }>('listRolePermissions', {roleId})
    }

    /**
     * 修改角色授权信息
     */
    updateRolePermissions = (rolePermissionReq: SysRolePermissionReq) => {
        return this.post<string, SysRolePermissionReq>('updateRolePermissions', rolePermissionReq)
    }

}

export default new SysRoleApi()